package fileReader.demo.reader;

import java.util.Vector;


/**
 * Map Layer is an abstract class that defines an interface for map data storages.
 */
public class MapLayer {

	private Box boundingBoxXY;
	private Box boundingBoxZM;
	private static Box globalBoundingBox = new Box(Double.MAX_VALUE,Double.MAX_VALUE,Double.MIN_VALUE,Double.MIN_VALUE);
	protected Vector data = new Vector();	// map symbols are stored in here
	private double scale_factor=0.0;
	
	/**
	 * This method sets the boundingboxXY.
	 * @param boundingBox value to set
	 */
	public void setBoundingBoxXY(Box boundingBox){
		this.boundingBoxXY=boundingBox;
	}
	
	/**
	 * This method sets the boundingbox.
	 * @param boundingBox value to set
	 */
	public void setBoundingBoxZM(Box boundingBox){
		this.boundingBoxZM=boundingBox;
	}

	/**
	 * @param scale_factor The scale_factor to set.
	 */
	public void setScale_factor(double scale_factor) {
		this.scale_factor = scale_factor;
	}
	/**
	 * @return Returns the scale_factor.
	 */
	public double getScale_factor() {
		return scale_factor;
	}
	
	public static double getGlobalMin_x()
	{
		return globalBoundingBox.getXMin();
	}
	
	
	public static double getGlobalMin_y()
	{
		return globalBoundingBox.getYMin();
	}

	
	public static double getGlobalMax_y()
	{
		return globalBoundingBox.getYMax();
	}
	

	
	public static double getGlobalMax_x()
	{
		return globalBoundingBox.getXMax();
	}

	/**
	 * @return Returns the globalBoundingBox.
	 */
	public static Box getGlobalBoundingBox() {
		return globalBoundingBox;
	}

	/**
	 * @param globalBoundingBox The globalBoundingBox to set.
	 */
	public static void setGlobalBoundingBox(Box globalBoundingBox) {
		MapLayer.globalBoundingBox = globalBoundingBox;
	}
	
	/**
	 * 
	 * @return data
	 */
	public Vector getData()
	{
		return data;
	}

	/**
	 * This method cleans the maplayer 
	 * by removing elements from vector.
	 */
	public void cleanMapLayer() {
		data.removeAllElements(); 
	}

	public void reduceData(int points) {
		int n=0;
		int vertexCount=0;
		
		 for (int i = 0 ; i < data.size() ; i++) {
			 PolyLineDrawer p = (PolyLineDrawer) data.get(i);
		    	if(p.getDepth()>=Simulator.getSelectedDepth()){
		    		vertexCount+=p.getVertexList().size();
		    	}
			 }
				
		n=vertexCount/points;
		
		for(int i=0; i<data.size(); i++)
		{
			((PolyLineDrawer)data.elementAt(i)).reduceData(n);
		}
	}
}
